package com.ruoyi.authors.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.authors.domain.PaperAuthors;
import com.ruoyi.authors.service.IPaperAuthorsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论文作者表Controller
 * 
 * @author ruoyi
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/authors/authors")
public class PaperAuthorsController extends BaseController
{
    @Autowired
    private IPaperAuthorsService paperAuthorsService;

    /**
     * 查询论文作者表列表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaperAuthors paperAuthors)
    {
        startPage();
        List<PaperAuthors> list = paperAuthorsService.selectPaperAuthorsList(paperAuthors);
        return getDataTable(list);
    }

    /**
     * 导出论文作者表列表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:export')")
    @Log(title = "论文作者表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperAuthors paperAuthors)
    {
        List<PaperAuthors> list = paperAuthorsService.selectPaperAuthorsList(paperAuthors);
        ExcelUtil<PaperAuthors> util = new ExcelUtil<PaperAuthors>(PaperAuthors.class);
        util.exportExcel(response, list, "论文作者表数据");
    }

    /**
     * 获取论文作者表详细信息
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paperAuthorsService.selectPaperAuthorsById(id));
    }

    /**
     * 新增论文作者表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:add')")
    @Log(title = "论文作者表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperAuthors paperAuthors)
    {
        return toAjax(paperAuthorsService.insertPaperAuthors(paperAuthors));
    }

    /**
     * 修改论文作者表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:edit')")
    @Log(title = "论文作者表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperAuthors paperAuthors)
    {
        return toAjax(paperAuthorsService.updatePaperAuthors(paperAuthors));
    }

    /**
     * 删除论文作者表
     */
    @PreAuthorize("@ss.hasPermi('authors:authors:remove')")
    @Log(title = "论文作者表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperAuthorsService.deletePaperAuthorsByIds(ids));
    }
}
